<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优惠券获取-{{$SEO['title']}}</title>
    <meta name="keywords" content="{{$SEO['keywords']}}"/>
    <meta name="description" content="{{$SEO['description']}}"/>
    <!--公用css引用-->
    @include('front.common.style')
            <!--END/公用css引用-->
    <link rel="stylesheet" href="{{asset('/dist/css/index.css')}}">
</head>
<body>
<!--公共头部-->
@include('front.common.header')

        <!--END/公共头部-->

@inject('recommendPositionService','App\Interfaces\RecommendPositionService')
@inject('goodsService','App\Interfaces\GoodsService')
@inject('shopService','App\Interfaces\ShopService')
@inject('pictureService','App\Interfaces\PictureService')
@inject('userCollectionService','App\Interfaces\UserCollectionService')

@inject('adService','App\Interfaces\AdService')
@inject('couponService','App\Interfaces\CouponService')

        <!--banner图-->
<!-- <div class="banner fn-rel">
    <ul id="js-banner" class="rslides">
    {{-- @if($adPosition) --}}
        {{-- @foreach($adService->get('cat_focus_'.$cat->cat_id) as $ad) --}}
            <li><a class="fn-clear img" href="{{-- $ad->url --}}" style="background: url('{{-- $pictureService::thumb($ad->image) --}}') no-repeat center;"></a></li>
        {{-- @endforeach --}}
    {{-- @else --}}
        {{-- @foreach($adService->get('index_focus') as $ad) --}}
            <li><a class="fn-clear img" href="{{-- $ad->url --}}" style="background: url('{{-- $pictureService::thumb($ad->image) --}}') no-repeat center;"></a></li>
        {{-- @endforeach --}}
    {{-- @endif --}}
    </ul>
    <div class="inbox rslides-nav"></div>
</div> -->
<!--END/banner图-->

<!-- content start -->

<!--筛选条件-->
<div class="inbox">
    <div class="filter-wrap fn-mt20">

        <!--已选择搜索条件、统计搜索结果-->
        <!-- <ul class="selected">
            <li class="fn-dib "><a href="#">已选条件：</a></li>
            <li class="fn-dib param"><a href="#">全平台<i class="close">×</i></a></li>
            <li class="fn-dib param"><a href="#">21-50<i class="close">×</i></a></li>
        </ul> -->
        <!--END/已选择搜索条件、统计搜索结果-->

        <!--搜索条件-->
        <ul class="params-list pt0">
            <li class="param-row">
                <div class="param-tit">分类：</div>
                <ul class="inner-list">
                    <li class="item @if(@$_GET['type']=='all')cur @endif"><a href="coupon?type=all">全部券@if(@$_GET['type']=='all')cur <i class="close">×</i>@endif</a></li>
                    <li class="item @if(@$_GET['type']=='1')cur @endif"><a href="coupon?type=1">全平台券@if(@$_GET['type']=='1')<i class="close">×</i>@endif</a></li>
                    <li class="item @if(@$_GET['type']=='2')cur @endif"><a href="coupon?type=2">商品券@if(@$_GET['type']=='2')<i class="close">×</i>@endif</a></li>
                    <li class="item @if(@$_GET['type']=='3')cur @endif"><a href="coupon?type=3">分类券@if(@$_GET['type']=='3')<i class="close">×</i>@endif</a></li>
                    <li class="item @if(@$_GET['type']=='4')cur @endif"><a href="coupon?type=4">店铺券@if(@$_GET['type']=='4')<i class="close">×</i>@endif</a></li>
                    <li class="item @if(@$_GET['type']=='5')cur @endif"><a href="coupon?type=5">品牌券@if(@$_GET['type']=='5')<i class="close">×</i>@endif</a></li>
                </ul>
            </li>
            <!-- <li class="param-row">
                <div class="param-tit">使用限额：</div>
                <ul class="inner-list">
                    <li class="item"><a href="#">0-20</a></li>
                    <li class="item cur"><a href="#">21-50 <i class="close">×</i></a></li>
                    <li class="item"><a href="#">51-100</a></li>
                    <li class="item"><a href="#">101-200</a></li>
                    <li class="item"><a href="#">200以上</a></li>
                </ul>
            </li> -->

        </ul>
        <!--END/搜索条件-->

        <!--排序-->
        <!-- <div class="sort">
            <div class="page-num fn-fr"><span class="total-result">共搜索到<span class="text-color-1">200</span>个结果</span><span class="text-color-2">1</span>/12</div>
            <span class="label">排序：</span>

            <span class="sort-param fn-dib down">最优推荐 <i class="icon icon-arrow-b3"></i><i class="icon icon-arrow-t3"></i></span>
            <span class="sort-param fn-dib up">最大折扣 <i class="icon icon-arrow-b3"></i><i class="icon icon-arrow-t3"></i></span>
        </div> -->
        <!--END/排序-->

    </div>
</div>

<!--END/筛选条件-->

<!--优惠券列表-->
<div class="inbox result-list coupon-list">
    <div class="panel-body">
        <div class="ui-cols-5">
<?php $current_time = date('Y-m-d H:i:s'); ?>
@foreach($coupons as $item)

    <div class="col">
        <div class="coupon-card">
            <!-- <div class="brand">
                <img src="{{asset('/images/home/brand.png')}}" alt="阿福易购">
            </div> -->

            <div class="txt fn-cf @if($current_time<$item->start_time || $current_time>$item->end_time ||$item->receive_amount>=$item->amount) txt-bg7 @endif" style="margin-top:10px;">

                <div class="fn-fl price"><span class="size14">￥</span><var class="size30 ">{{$item->value}}</var></div>
                @if($current_time>$item->end_time)
                    <div class="fn-fl get-btn">已过期</div>
                @elseif($item->receive_amount>=$item->amount)
                    <div class="fn-fl get-btn">已领完</div>
                @else

                    <div class="J-getCoupon fn-fl get-btn" data-id="{{$item->id}}" data-price="{{$item->value}}" data-name="{{$item->name}}" data-time="{{date('Y.m.d', strtotime ($item->end_time))}}" data-reg="满{{$item->limit_fir}}减{{$item->value}}" data-num="1"><span class="t">立即领取&gt;</span></div>
                @endif
            </div>
        </div>
    </div>

@endforeach

        </div>


        <!--分页-->
        <!--  fn-tl/fn-tc/fn-tr 左中右定位; pager-big 大尺寸分页 可不加-->
        <div class="pager pager-big fn-tr">
            {!! $coupons->appends(['type' => $search['type']])->render() !!}
        </div>
        <!--END/分页-->

    </div>
</div>
<!--END/优惠券列表-->

<!-- content end -->




<!--公共尾部-->
@include('front.common.footer')

<!--END/公共尾部-->


<!--公用js引用-->
@include('front.common.script')

<!--END/公用js引用-->



<script type="text/html" id="couponTpl">
    <p class="t-gray0 size14">您正在免费领取</p>
    <p class="fn-mt10 size20"><span class="t-red1">${num}</span>张   <span class="t-red1">${name}  ${price}元</span>优惠券（${reg}）</p>
    <p class="fn-mt20 small t-gray6 size12">
        优惠劵有效期至${time} <br>
        每个ID限领${num}张
    </p>

</script>

<script src="{{asset('/js/responsiveslides.min.js')}}"></script>
<script src="{{asset('/js/scroll.js')}}"></script>
<script src="{{asset('/js/home.js')}}"></script>
<script>
    //领取优惠券
    $('.J-getCoupon').on('click',function(){
        var btn=$(this),
            id=btn.data('id'),
            name=btn.data('name'),
            time=btn.data('time'),
            reg=btn.data('reg'),
            price=btn.data('price'),
            num=btn.data('num');

        var data={
            id:id,
            name:name,
            time:time,
            reg:reg,
            price:price,
            num:num
        };

        var tpl =$('#couponTpl').html();
        var html =tools.htmlTemplate(tpl,data);

        //询问框
        layer.confirm(html, {
            title:'提示',
            btn: ['确定','取消'] //按钮
        }, function(){

            var dataForm = {};
            dataForm.coupon_id = id;
            var urls = "/my/coupon";

            $.ajax({
                type: "POST",
                url: urls,
                data: dataForm,
                dataType: "json",
                headers: {
                    'X-CSRF-Token': "{{csrf_token()}}"
                },
                async:true,
                cache:false,
                success: function (msg) {

                    if(msg.status){
                        layer.msg('领完成功', {icon: 1});

                    }//end if()

                }
            }); //end ajax


        }, function(){});
    });
</script>
</body>
</html>